package com.carl.zlds.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carl.zlds.dao.sqlprovider.GameAccountSqlProvider;
import com.carl.zlds.model.GameAccount;
import com.carl.zlds.pojo.dto.AccountSearchDTO;
import com.carl.zlds.pojo.vo.GameAccountVO;
import com.carl.zlds.pojo.vo.GameDealStatVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * @author carl
 */
public interface GameAccountMapper extends BaseMapper<GameAccount> {
    @SelectProvider(type = GameAccountSqlProvider.class, method = "getGameAccountList")
    List<GameAccountVO> getGameAccountList(@Param("gameId") Long gameId, @Param("status") Integer status, @Param("limitSql") String limitSql);

    @SelectProvider(type = GameAccountSqlProvider.class, method = "getGameAccountList")
    Integer countGameAccountList(@Param("gameId") Long gameId, @Param("status") Integer status, @Param("limitSql") String limitSql);

    @Select("select ga.*, gad.content as content from game_account ga left join game_account_detail gad on ga.id = gad.game_account_id" +
            " where ga.weight >= 0 and ga.game_id = #{gameId} and ga.id = #{id}")
    GameAccountVO queryGameAccountInfo(@Param("gameId") Long gameId, @Param("id") Long id);

    @Select("select date_format(update_time, '%Y-%m-%d') date, count(*) count from game_account where weight = 0 " +
            "and game_id = #{gameId} and status = 2 and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(update_time) > 0 " +
            "and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(update_time) < 4 " +
            "group by date_format(update_time, '%Y-%m-%d') order by date_format(update_time, '%Y-%m-%d') desc")
    List<GameDealStatVO> statDealForCurrent3Days(@Param("gameId") Long gameId);

    @Select("select * from game_account where game_id = #{gameId} and status = 1 and weight >= 0 " +
            "and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(launch_time) = 1 limit #{limit}")
    List<GameAccount> getHomeLatest1List(@Param("gameId") Long gameId, @Param("limit") Integer limit);

    @Select("select * from game_account where game_id = #{gameId} and status = 1 and weight >= 0 " +
            "and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(launch_time) < 7 limit #{limit}")
    List<GameAccount> getHomeLatest7List(@Param("gameId") Long gameId, @Param("limit") Integer limit);

    @Select("select date_format(update_time, '%Y-%m-%d') date, img from game_account where weight = 0 " +
            "and game_id = #{gameId} and status = 2 and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(update_time) = 1 " +
            "order by update_time desc limit 1")
    GameDealStatVO getImgForCurrent1Day(@Param("gameId") Long gameId);

    @Select("select date_format(update_time, '%Y-%m-%d') date, img from game_account where weight = 0 " +
            "and game_id = #{gameId} and status = 2 and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(update_time) = 2 " +
            "order by update_time desc limit 1")
    GameDealStatVO getImgForCurrent2Day(@Param("gameId") Long gameId);

    @Select("select date_format(update_time, '%Y-%m-%d') date, img from game_account where weight = 0 " +
            "and game_id = #{gameId} and status = 2 and to_days(DATE_FORMAT(now(),'%Y-%m-%d')) - to_days(update_time) = 3 " +
            "order by update_time desc limit 1")
    GameDealStatVO getImgForCurrent3Day(@Param("gameId") Long gameId);

    @SelectProvider(type = GameAccountSqlProvider.class, method = "getAccountSearch")
    List<GameAccountVO> getAccountSearch(@Param("dto") AccountSearchDTO accountSearchDTO, @Param("limitSql") String limitSql);

    @SelectProvider(type = GameAccountSqlProvider.class, method = "getAccountSearch")
    Integer countAccountSearch(@Param("dto") AccountSearchDTO accountSearchDTO, @Param("limitSql") String limitSql);
}
